package com.mcptt.db.model;

import android.content.ContentValues;
import android.database.Cursor;
import android.database.DatabaseUtils;

import com.mcptt.comm.CommonFunc;
import com.mcptt.db.DbConst;

public class ConfigFileInfo
{
    private String fileName = "";
    private String eTag = "";
    private String content = "";
    private String date = "";

    public ConfigFileInfo(String fileName,String eTag,String content)
    {
	this.fileName = fileName;
	this.eTag = eTag;
	this.content = content;
    }

    public ConfigFileInfo(Cursor c)
    {
	ContentValues args = new ContentValues();
	DatabaseUtils.cursorRowToContentValues(c, args);
	createFromContentValue(args);
    }

    public boolean isValid()
    {
	if(eTag != null
		&& eTag.length() > 0
		&& content != null
		&& content.length() > 0)
	{
	    return true;
	}
	return false;
    }

    public final void createFromContentValue(ContentValues args) {

	String tmp_s;

	//       tmp_s = args.getAsString(DbConst.COL_UID);
	//       if(tmp_s != null) {
	//       	uId = tmp_s;
	//       }
	tmp_s = args.getAsString(DbConst.COL_FileName);
	if(tmp_s != null) {
	    fileName = tmp_s;
	}
	tmp_s = args.getAsString(DbConst.COL_ETag);
	if(tmp_s != null) {
	    eTag = tmp_s;
	}
	tmp_s = args.getAsString(DbConst.COL_ConfigContent);
	if(tmp_s != null) {
	    content = tmp_s;
	}
	tmp_s = args.getAsString(DbConst.COL_Date);
	if(tmp_s != null) {
	    date = tmp_s;
	}
    }

    public ContentValues getContentValues() {
	ContentValues cv = new ContentValues();
	cv.put(DbConst.COL_FileName, fileName);
	cv.put(DbConst.COL_ETag,eTag);
	cv.put(DbConst.COL_ConfigContent, content);
	cv.put(DbConst.COL_Date, CommonFunc.getDateAndTime());

	return cv;
    }

    public ContentValues getGroupContentValues() {
	ContentValues cv = new ContentValues();
	cv.put(DbConst.COL_GroupName, fileName);
	cv.put(DbConst.COL_ETag,eTag);
	cv.put(DbConst.COL_ConfigContent, content);
	cv.put(DbConst.COL_Date, CommonFunc.getDateAndTime());

	return cv;
    }

    public String getFileName()
    {
	return fileName;
    }
    public String geteTag()
    {
	return eTag;
    }
    public String getContent()
    {
	return content;
    }
    public String getDate()
    {
	return date;
    }

    public String toString()
    {
	StringBuffer buffer = new StringBuffer("ConfigFileInfo:");
	buffer.append("fileName = ").append(fileName).append(",");
	buffer.append("eTag = ").append(eTag).append(",");
	buffer.append("content = ").append(content).append(",");
	buffer.append("date = ").append(date).append(";");

	return buffer.toString();
    }
}
